﻿using System.Text.Json;

var person = new Person
{
    FirstName = "Castle",
    LastName = "Moriarty",
    YearOfBirth = 1880
};


var asJson = JsonSerializer.Serialize(person);
Console.WriteLine("As Json");
Console.WriteLine(asJson);

Console.ReadKey();

public class Person
{
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public int YearOfBirth { get; set; }
}